<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style>
        .box {
            display: flex;
            justify-content: space-around;
        }

        .box .box__button {
            width: 100px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            cursor: pointer;
            user-select: none;
            border: 1px solid #000;
        }

        .box .box__button.active {
            color: green;
            background-color: yellow;
        }

        .button {}

        .button.active {
            color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <h2>综合排序，可多选</h2>
        <div class="box">
            <!-- <div class="box__button">点评高分</div>
        <div class="box__button">优惠商家</div>
        <div class="box__button active">满减优惠</div>
        <div class="box__button">品牌商家</div> -->

            <div class="box__button" :class="{active: checkedIds.includes(item.id)}" v-for="item in filterButtons"
                :key="item.id" @click="fn1(item.id)">
                {{ item.name }}
            </div>
        </div>

        <h2>Tab 切换</h2>
        <div>
            <!-- <button class="button active">Tab A</button>
            <button class="button">Tab B</button>
            <button class="button">Tab C</button> -->

            <button 
                class="button" 
                :class="{ active: curTabId === item.id }"
                v-for="item in tabs" 
                :key="item.id"
                @click="curTabId = item.id"
                >
                {{item.name}}
            </button>
        </div>
        <div v-if="curTabId === '001'">Tab A 的内容</div>
        <div v-if="curTabId === '002'">Tab B 的内容</div>
        <div v-if="curTabId === '003'">Tab C 的内容</div>
    </div>

    <script src="./js/vue.js"></script>
    <script>
        new Vue({
            el: "#app",
            data() {
                return {
                    checkedIds: ['001'], // 存放多选的id
                    filterButtons: [
                        { id: "001", name: "点评高分" },
                        { id: "002", name: "优惠商家" },
                        { id: "003", name: "满减优惠" },
                        { id: "004", name: "品牌商家" },
                    ],

                    curTabId: '001', // 当前高亮的Tab的Id
                    tabs: [
                        { id: "001", name: "Tab A" },
                        { id: "002", name: "Tab B" },
                        { id: "003", name: "Tab C" },
                    ],


                };
            },
            methods: {
                fn1(id) {
                    // 点一下高亮，又点一下取消高亮
                    const index = this.checkedIds.findIndex(iid => iid === id)
                    if (index > -1) {
                        // 存在
                        this.checkedIds.splice(index, 1)
                    } else {
                        // 不存在
                        this.checkedIds.push(id)
                    }

                }
            }
        });
    </script>
</body>

</html>